package com.senven.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String input = "redrum ... redrum";
        new MyAsyncTask().execute(input);

        //获取View Model 实例
        MyViewModel myViewModel = ViewModelProviders.
                of(this).get(MyViewModel.class);

        // 获取当前的数据并观察
        myViewModel.getData().observe(this, new Observer<List<String>>() {
            @Override
            public void onChanged(List<String> strings) {
                // 使用加载的数据更新UI
                // 配置更改后，自动返回缓存数据
                // 若底层的LiveData对象被修改，将被再次触发
            }
        });

    }
}